/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.xml.sax.SAXException;

/**
 *
 * @author Leandro
 */
@ManagedBean(name="ControladorVisorVariables")
@RequestScoped
public class ControladorVisorVariables {
    private List<DtoVariable> variables;
    private ExpertoXml expertoXml;
    private String archivo="lecturas.xml";

    public List<DtoVariable> getVariables() {
        variables=findVariables();
        
        return variables;
    }

    public void setVariables(List<DtoVariable> variables) {
        this.variables = variables;
    }


    /** Creates a new instance of ControladorVisorVariables */
    public ControladorVisorVariables() {
        this.variables=findVariables();
    }

    private List<DtoVariable> findVariables() {
        List<DtoVariable> rta = null;
        List<DtoMensaje> msjs = null;
        if(expertoXml==null){
            try {
                expertoXml = new ExpertoXml();
            } catch (SAXException ex) {
                Logger.getLogger(ControladorVisorVariables.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        try {
            msjs = expertoXml.leerVariables(archivo);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ControladorVisorVariables.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ControladorVisorVariables.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SAXException ex) {
            Logger.getLogger(ControladorVisorVariables.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(msjs!=null){
            //Procesar y sacar el ultimo
        }
        return rta;
    }


}
